BlazeComponent.extendComponent({
  onCreated() {
    this.subscribe('archivedMindMaps');
  },

  archivedMindMaps() {
    return MindMaps.find(
      { archived: true },
      {
        sort: { modifiedAt: -1 },
      },
    );
  },

  events() {
    return [
      {
        'click .js-restore-mindMap'() {
          //  const mindMap = this.currentData();
          Meteor.call('restoreMindMap', this.currentData()._id);
          //  mindMap.restore();
          const mindMapId = this.currentData()._id;
          const mindMapUrl = `/mindMap/dist/index.html?mindMapId=${mindMapId}`;
          window.location.href = mindMapUrl;
        },
        'click .js-delete-mindMap': Popup.afterConfirm(
          'mindMapDelete',
          function() {
            Popup.close();
            MindMaps.remove(this._id);
            if (Utils.isMiniScreen()) {
              FlowRouter.go('home');
            } else {
              FlowRouter.go('newHome');
            }
          },
        ),
      },
    ];
  },
}).register('archivedMindMaps');
